package junk;
import java.util.ArrayList;


import processing.core.PApplet;

class Gene implements Comparable
{
	public static Gene[] geneList;
	public static ArrayList<Gene> selectedGenes;
	
	public PApplet parent;
	public String name;
	public double x;
	public double y;
	public ArrayList<String> annotations;
	
	public ArrayList<float[]> expressionConditions;
	public float x1, y1 ,geneSize;
	public boolean isSelected;
	public Annotations[] groupHeigherarchy;
	public int numAnnotations;
	public int color;
	public boolean active;
	public boolean flagged;
	public Annotations activeAnnotation;
	public ArrayList<float[]> percentExpressionConditions; 
	
	
	public Gene( PApplet p)
	{
		annotations = new ArrayList<String>();
		parent = p;
		groupHeigherarchy = new Annotations[5];
		expressionConditions = new ArrayList<float[]>();
		percentExpressionConditions = new ArrayList<float[]>();
		numAnnotations = 0;
		active = true;
		percentExpressionConditions = new ArrayList<float[]>();
	}
	public void addExpression( float[] exp )
	{
		expressionConditions.add(exp);
		float sum = 0;
		for(int i = 0; i< exp.length; i++)
			sum = sum + Math.abs(exp[i]);
		float[] percentages = new float[exp.length];
		for(int i = 0; i< exp.length; i++)
		{
			if(sum> 0) percentages[i] = Math.abs(exp[i])/sum; 
			else percentages[i] = 0;
		}
		percentExpressionConditions.add(percentages);
	}

	
	public String[] geneDetails()
	{
		String[] geneDetails ={"\nGene name: \t\t\t" + name, "\nAlternate Name: \t\t"+ annotations.get(1), 
		"\nProcess: \t\t\t"+ annotations.get(2) , "\nFunction: \t\t\t" + annotations.get(3) , "\nCellular Component: \t\t"
		+ annotations.get(4),  "\nStress Classification: \t\t" + annotations.get(5) , "\nPheremone Classification: \t"
		+ annotations.get(6) , "\nCell Cycle Classification: \t" + annotations.get(7) , "\nARS: \t\t\t\t" + annotations.get(8)};
		return geneDetails;
	}
	public void drawGene() {
		float radius = Main1.innerRadius*.99f;
		int column = Main1.ringProtein.columnInData;
		int dataset = -1;		
		for( int i = 0; i< ReadGenes.datasets.length; i++)
		{
			if(Main1.ringProtein.set.equals(ReadGenes.datasets[i]))
				dataset = i;
		}	
		if(Main1.uniformGeneSize)
			geneSize = parent.width*.03f/(float)Math.sqrt(Main1.firstAnnotation.genes.length);
		else if(Main1.ringProtein.type.equals("Raw"))
		{
			if(Main1.fractionExpression) geneSize = (float) ((float)parent.width*.11*Math.pow(percentExpressionConditions.get(dataset)[column],2));
			else geneSize = (float)(Math.pow(Math.abs(expressionConditions.get(dataset)[column]),.7)*(float) ((float)parent.width*.56f/Math.sqrt(Main1.firstAnnotation.genes.length)));
		}
		else
			geneSize = (float)((Math.pow(1.0 - expressionConditions.get(dataset)[column],10)+.1f)*(float)parent.width*.003f);
		if(flagged) geneSize = (float) ((float)parent.width*.5/Math.sqrt(Main1.firstAnnotation.genes.length));
		
		x1 =  (float) (x * radius);
		y1 =  (float) (-y * radius);
		if(Main1.ringProtein.type.equals("Raw"))
		{
			if (expressionConditions.get(dataset)[column] > 0)
				color = parent.color(255,0,0);
			else 
				color = parent.color(0,255,0);
		}
		else
			color = 255;
		if (isSelected)  color = parent.color(255,255,0);
		if(!Main1.lighter) parent.fill(color);
		else parent.fill(Main1.blendColor(parent.color(255),parent.color(color), Main1.SUBTRACT));
		parent.noStroke();
		parent.ellipse(x1,y1,geneSize,geneSize);
	}
	public void checkMouseOver()
	{
		if((parent.mouseX-parent.width/2 + Main1.xTranslate) > (x1- geneSize/2) && (parent.mouseX-parent.width/2 +Main1.xTranslate) < (x1 + geneSize/2))
			if((parent.mouseY-parent.height/2) > (y1- geneSize) && (parent.mouseY-parent.height/2) < (y1 + geneSize))
				{
					isSelected = !isSelected;
					if(isSelected)
					{
						if(Main1.selectedGene != null) Main1.selectedGene.isSelected = false;
						Main1.expandPopup = false;
						Main1.isolate = false;
						Main1.selectedGene = this;
					}
					else 
						Main1.selectedGene = null;
				}
				
	}
	public int compareTo(Object arg0) {
		return (this.toString().compareToIgnoreCase(arg0.toString()));
	}
	
	public String toString() 
	{
		return name;
	}
	
	
}